package main

import (
	"fmt"
	"sync"
)

func main() {
	var once sync.Once
	onceFun := func() {
		fmt.Println("test only once")
	}
	done := make(chan bool)
	for i := 0; i < 6; i++ {
		go func() {
			once.Do(onceFun) //开启6个goroutine，onceFun只会被执行1次
			done <- true
		}()
	}
	for i := 0; i < 6; i++ {
		<-done //等待6个goroutine完成
	}
}
